//
// Created by 吴锐 on 2022/2/27.
//

#include "iostream"

using namespace std;

template<class T>
void mySwap(T &a, T &b) {
    T temp = a;
    a = b;
    b = temp;
}

template<class T>
void mySort(T arr[], int len) {
    for (int i = 0; i < len; i++) {
        int max = i;
        for (int j = i + 1; j < len; j++) {
            if (arr[max] < arr[j]) {
                max = j;
            }
        }
        if (max != i) {
            mySwap(arr[max], arr[i]);
        }
    }
}

template<class T>
void printArray(T arr[], int len) {
    for (int i = 0; i < len; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;
}

void test01() {
    char charArr[] = "badcef";
    int length = sizeof(charArr) / sizeof(charArr[0]);
    mySort(charArr, length);
    printArray(charArr, length);
}

void test02() {
    int intArr[] = {7, 5, 3, 8, 11, 22, 4, 5, -1};
    int length = sizeof(intArr) / sizeof(intArr[0]);
    mySort(intArr, length);
    printArray(intArr, length);
}

int main() {
//    test01();
    test02();
    return 0;
}